# -*- coding: utf-8 -*-

from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save

#######################################################################
####################  Enumeration  ####################################
LOCATION = (
                (0, u'서울시'),
                (1, u'부산시'),
                (2, u'인천시'),
                (3, u'대전시'),
                (4, u'광주시'),
                (5, u'대구시'),
                (6, u'제주시'),
                (7, u'경기도'),
                (8, u'강원도'),
                (9, u'충청북도'),
                (10, u'충청남도'),
                (11, u'전라북도'),
                (12, u'전라남도'),
                (13, u'경상북도'),
                (14, u'경상남도'),

        )
SEX = (
                (0, u'Male'),
                (1, u'Female'),
        )

#######################################################################
####################  Member ##########################################

# << entity >>

class Member(models.Model):

        # django-User 사용 https://docs.djangoproject.com/en/dev/topics/auth/
        user = models.OneToOneField(User)

        #주소값 수정
        photo = models.ImageField(upload_to='/MemberPhoto/', default='default.jpg')
        name = models.CharField(max_length = 20)
        introduction = models.TextField(blank = True)
        location = models.PositiveSmallIntegerField(null=True, choices=LOCATION)
        sex = models.PositiveSmallIntegerField(null=True, choices=SEX)
        private_protect = models.NullBooleanField()

	def __unicode__(self):
		return u"%s // %s" % (self.user, self.name)
      
#만약 Django-User가 생성되면 Member도 자동 생성
def create_user_profile(sender, instance, created, **kwargs):
    if created:
       member, created = Member.objects.get_or_create(user=instance)

post_save.connect(create_user_profile, sender=User)
